home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / MENUBAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-07  |  6.0 KB  |  241 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <STRING.H>
  9. #include <VDI.H>
  10. #include <memory.h>
  11. #include "XA_DEFS.H"
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "K_DEFS.H"
  15. #include "RECTLIST.H"
  16. #include "OBJECTS.H"
  17. #include "OBJCWIDG.H"
  18. #include "SYSTEM.H"
  19. #include "C_WINDOW.H"
  20. #include "RESOURCE.H"
  21. #include "RECTLIST.H"
  22.  
  23. /*
  24.     This file provides the interface between XaAES's (somewhat strange) menu
  25.     system and the standard GEM calls. Most GEM apps will only care about the
  26.     menu they install onto the desktop, although XaAES can allow seperate menu's
  27.     for each window.....
  28. */
  29.  
  30. /*
  31.     Install a menu bar onto the desktop window
  32. */
  33. unsigned long XA_menu_bar(short clnt_pid, AESPB *pb)
  34. {
  35.     XA_RECT_LIST *rl;
  36.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  37.     
  38.     pb->intout[0]=1;
  39.     
  40.     switch(pb->intin[0])
  41.     {
  42.         case MENU_INSTALL:
  43.             fix_menu((OBJECT*)pb->addrin[0]);    /* do a special fix on menu the menu  */
  44.             clients[clnt_pid].std_menu=(OBJECT*)pb->addrin[0];
  45.             menu_bar->tree=(OBJECT*)(pb->addrin[0]);
  46.             menu_bar->owner=clnt_pid;
  47.  
  48.             rl=rect_get_system_first(root_window);
  49.  
  50.             v_hide_c(V_handle);
  51.             while(rl)
  52.             {
  53.                 set_clip(rl->x, rl->y, rl->w, rl->h);
  54.                 display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  55.                 rl=rect_get_system_next(root_window);
  56.             }
  57.             clear_clip();
  58.             v_show_c(V_handle,1);
  59.             
  60.             break;
  61.         case MENU_REMOVE:
  62.             clients[clnt_pid].std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  63.             menu_bar->owner=AESpid;
  64.             menu_bar->tree=clients[clnt_pid].std_menu;
  65.         
  66.             rl=rect_get_system_first(root_window);
  67.  
  68.             v_hide_c(V_handle);
  69.             while(rl)
  70.             {
  71.                 set_clip(rl->x, rl->y, rl->w, rl->h);
  72.                 display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  73.                 rl=rect_get_system_next(root_window);
  74.             }
  75.             clear_clip();
  76.             v_show_c(V_handle,1);
  77.             break;
  78.             
  79.         case MENU_INQUIRE:
  80.             pb->intout[0]=menu_bar->owner;
  81.             break;
  82.     }
  83.     
  84.     return XAC_DONE;
  85. }
  86.  
  87. /*
  88.     Highlight / un-highlight a menu title
  89.     -actually, this isn't really needed as XaAES cancels the highlight itself....
  90.     ...it's only here for compatibility. 
  91. */
  92. unsigned long XA_menu_tnormal(short clnt_pid, AESPB *pb)
  93. {
  94.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  95.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  96.     
  97.     if (pb->intin[1])            /* Change the highlight / normal status of a menu title */
  98.         tree[pb->intin[0]].ob_state&=~SELECTED;
  99.     else
  100.         tree[pb->intin[0]].ob_state|=SELECTED;
  101.  
  102. /* If we just changed the main root window's menu, better redraw it */
  103.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  104.     {
  105.         XA_RECT_LIST *rl=rect_get_system_first(root_window);
  106.  
  107.         v_hide_c(V_handle);
  108.         while(rl)
  109.         {
  110.             set_clip(rl->x, rl->y, rl->w, rl->h);
  111.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  112.             rl=rect_get_system_next(root_window);
  113.         }
  114.         clear_clip();
  115.         v_show_c(V_handle,1);
  116.     }
  117.     
  118.     pb->intout[0]=1;
  119.     
  120.     return XAC_DONE;
  121. }
  122.  
  123. /*
  124.     Enable/Disable a menu item
  125. */
  126. unsigned long XA_menu_ienable(short clnt_pid, AESPB *pb)
  127. {
  128.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  129.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  130.     
  131.     if (pb->intin[1])            /* Change the disabled status of a menu item */
  132.         tree[pb->intin[0]].ob_state&=~DISABLED;
  133.     else
  134.         tree[pb->intin[0]].ob_state|=DISABLED;
  135.     
  136. /* If we just changed the main root window's menu, better redraw it */
  137.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  138.     {
  139.         XA_RECT_LIST *rl=rect_get_system_first(root_window);
  140.  
  141.         v_hide_c(V_handle);
  142.         while(rl)
  143.         {
  144.             set_clip(rl->x, rl->y, rl->w, rl->h);
  145.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  146.             rl=rect_get_system_next(root_window);
  147.         }
  148.         clear_clip();
  149.         v_show_c(V_handle,1);
  150.     }
  151.     pb->intout[0]=1;
  152.  
  153.     return XAC_DONE;
  154. }
  155.  
  156. /*
  157.     Check / un-check a menu item
  158. */
  159. unsigned long XA_menu_icheck(short clnt_pid, AESPB *pb)
  160. {
  161.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  162.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  163.     
  164.     if (pb->intin[1])            /* Change the disabled status of a menu item */
  165.         tree[pb->intin[0]].ob_state|=CHECKED;
  166.     else
  167.         tree[pb->intin[0]].ob_state&=~CHECKED;
  168.     
  169. /* If we just changed the main root window's menu, better redraw it */
  170.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  171.     {
  172.         XA_RECT_LIST *rl=rect_get_system_first(root_window);
  173.  
  174.         v_hide_c(V_handle);
  175.         while(rl)
  176.         {
  177.             set_clip(rl->x, rl->y, rl->w, rl->h);
  178.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  179.             rl=rect_get_system_next(root_window);
  180.         }
  181.         clear_clip();
  182.         v_show_c(V_handle,1);
  183.     }
  184.     
  185.     pb->intout[0]=1;
  186.  
  187.     return XAC_DONE;
  188. }
  189.  
  190. /*
  191.     Change a menu item's text
  192. */
  193. unsigned long XA_menu_text(short clnt_pid, AESPB *pb)
  194. {
  195.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  196.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  197.     char *text=(char*)pb->addrin[1];
  198.     
  199.     strcpy((char*)tree[pb->intin[0]].ob_spec,text);
  200.     
  201. /* If we just changed the main root window's menu, better redraw it */
  202.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  203.     {
  204.         XA_RECT_LIST *rl=rect_get_system_first(root_window);
  205.  
  206.         v_hide_c(V_handle);
  207.         while(rl)
  208.         {
  209.             set_clip(rl->x, rl->y, rl->w, rl->h);
  210.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  211.             rl=rect_get_system_next(root_window);
  212.         }
  213.         clear_clip();
  214.         v_show_c(V_handle,1);
  215.     }
  216.     
  217.     pb->intout[0]=1;
  218.  
  219.     return XAC_DONE;
  220. }
  221.  
  222. /*
  223.     Register an apps 'pretty' & 'official' names.
  224. */
  225. unsigned long XA_menu_register(short clnt_pid, AESPB *pb)
  226. {
  227.     short f;
  228.     
  229.     if (pb->intin[0]!=-1)
  230.     {
  231.         strcpy(clients[clnt_pid].name,(char*)pb->addrin[0]);
  232.     }else{
  233.         strncpy(clients[clnt_pid].proc_name,(char*)pb->addrin[0],8);
  234.         for(f=strlen(clients[clnt_pid].proc_name); f<8; f++)
  235.             clients[clnt_pid].proc_name[f]=' ';
  236.         clients[clnt_pid].proc_name[8]='\0';
  237.     }
  238.     
  239.     return XAC_DONE;
  240. }
  241.